package cn.group01.git.service.impl;

import cn.group01.git.common.CodeMsg;
import cn.group01.git.common.ResponseResult;
import cn.group01.git.dto.LogPageDTO;
import cn.group01.git.entity.LogInfo;
import cn.group01.git.mapper.LogMapper;
import cn.group01.git.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;


    public ResponseResult list(LogPageDTO logPageDTO) {
        PageHelper.startPage(logPageDTO.getPage(),logPageDTO.getLimit());
        List<LogInfo> logInfos = logMapper.getList(logPageDTO.getUsername());
        PageInfo<LogInfo> infoPageInfo = new PageInfo<LogInfo>(logInfos);

        List<LogInfo> list = infoPageInfo.getList();
        long total = infoPageInfo.getTotal();

        return ResponseResult.success(CodeMsg.SUCCESS,list,total);
    }


    public void addLog(LogInfo logInfo) {
        logMapper.addLog(logInfo);
    }
}
